<template>
  <div class="hello">
    <h1>Hello World</h1>
    <p>{{ msg }}</p>
    <p>{{ $store.state.msg }}</p>
    <button @click="changeMsg">修改msg</button>
    <hr>

    <p>{{ name }}</p>
    <p>{{ age }}</p>
    <button @click="changeName">修改name</button>
    
  </div>
</template>

<script>
import {mapState} from 'vuex'

export default {
  name: 'HelloWorld',
  data(){
    return {
      msg: null
    }
  },
  mounted(){
    // console.log(this.$store)
    this.msg = this.$store.state.msg

    console.log(mapState(['name', 'age'])) // 获取Vuex的state中的数据
  },
  computed: mapState(['name', 'age']),
  methods: {
    changeMsg(){
      this.$store.dispatch('setMessage')
      // console.log(this.$store.state.msg)
      // console.log(this.msg)
    },
    changeName(){
      
    }
  }
 
}
</script>

<style scoped lang="less">
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
